OpenRoads Designer CONNECT Edition SDK Help

Spiral creator

Description

  • This is a custom interactive tool for creating spiral using point.

  • The user is prompted for one point. Later on, hard coded values are used to create spiral including the selected point by user. On spiral creation, horizontal alignment is created using it.

  • The SpiralCreator class which extends DgnElementSetTool which handles different events to interact with UI, the SpiralCreator class overrides the events here in this tool.

Remarks

  • This sample code is a part of ManagedSDKExample which you get with SDK installation under "examples" section in SDK installation directory.

  • If you encounter any error while using DgnElementSetTool class, make sure to add a reference to Bentley.DgnDisplayNet.dll by selecting Project > Add Reference or change the projects .csproj file to add reference to this dll.

  • The default dll location will be "C:\Program Files\Bentley\OpenRoads Designer CE 10.11\OpenRoadsDesigner\Bentley.DgnDisplayNet.dll".

Source Code


//Required References
using Bentley.DgnPlatformNET;
using Bentley.DgnPlatformNET.Elements;
using Bentley.CifNET.LinearGeometry;
using Bentley.GeometryNET;
using Bentley.CifNET.SDK.Edit;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.GeometryModel.SDK.Edit;

namespace ManagedSDKExample
    {
    class SpiralCreator : DgnElementSetTool
        {
        internal static DgnModel activeModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();
        internal static ModelInfo info = activeModel.GetModelInfo();
        private double UOR_TO_MASTER = 1.0 / info.UorPerMeter;

        /*----------------------------------------------------------------------------------------------**/
        /* Write Function | The user is prompted to place a point, where a spiral is then created from code.
        /*--------------+---------------+---------------+---------------+---------------+----------------*/
        internal void CreateSpiralFromPoints(DPoint3d startPoint)
            {
            //adjusts x and y values
            startPoint.X *= UOR_TO_MASTER;
            startPoint.Y *= UOR_TO_MASTER;
            startPoint.Z *= UOR_TO_MASTER;

            //creates new spiral
            Spiral spiral = new Spiral(startPoint, 0.0, 1000.0, 2000, 0.0, SpiralType.Clothoid, Hand.Clockwise);
            if (spiral == null)
                return;

            ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
            GeometricModel gm = con.GetOrCreateGeometricModel();

            if (gm == null)
                {
                con.Close();
                con.Dispose();
                return;
                }

            con.StartTransientMode();
            Bentley.CifNET.GeometryModel.SDK.Alignment al = gm.CreateAlignmentByLinearElement(spiral, true);
            con.PersistTransients();
            }

        protected override void OnPostInstall()
            {
            NotificationManager.OutputPrompt("Select first data point.");
            BeginDynamics();
            }

        //gets point
        protected override bool OnDataButton(DgnButtonEvent ev)
            {
            CreateSpiralFromPoints(ev.Point);
            NotificationManager.OutputPrompt("Select first data point or pick element selection tool to exit command.");
            return false;
            }
        
        protected override void OnRestartTool()
            {
            InstallNewInstance();
            }

        public override StatusInt OnElementModify(Element element)
            {
            return StatusInt.Error;
            }

        public static void InstallNewInstance()
            {
            SpiralCreator tool = new SpiralCreator();
            tool.InstallTool();
            }
        }
    }